package com.miyake.dsp.circuit;

import com.miyake.dsp.ComplexArray;
import com.miyake.dsp.Processor;
import com.miyake.dsp.ScilabExecute;

public class RcScilab implements Processor {

	private RcSetting setting;
	private ComplexArray source;

	public RcScilab(RcSetting setting) {
		this.setting = setting;
	}

	@Override
	public void setSource(ComplexArray source) {
		this.source = source;
	}

	@Override
	public ComplexArray getSource() {
		return this.source;
	}

	@Override
	public ComplexArray getProcessed() {
		String command = getCommand();
		return ScilabExecute.execute(command, source, "yhz");
	}

	@Override
	public Object getSetting() {
		return this.setting;
	}
	private String getCommand() {
		double t = 1 / setting.getFrequency();
		int point = 10000;
		String cmd = "r=" + String.valueOf(setting.getResistance()) + ";" 
			+ "l=0;c=" + String.valueOf(setting.getCapacitance()) 
			+ ";t=linspace(0,"  
			+ String.valueOf(t * /*10000*/point) + "," + String.valueOf(point) + ");"
			+ "s=poly(0,'s');G=(1/(c*s))/(r+l*s+1/(c*s));sys=syslin('c',G);y=csim('impuls',t,sys);yhz=convol(data1,y);";
//			+ "s=poly(0,'s');G=(1/(c*s))/(r+l*s+1/(c*s));sys=syslin('c',G);yhz=csim('impuls',t,sys);";

			return cmd;
	}
}
